#
# @lc app=leetcode.cn id=7 lang=python3
#
# [7] 整数反转
#

# @lc code=start


class Solution:
    def reverse(self, x: int) -> int:
        num, r = abs(x), 0
        bianjie = (1 << 31) - 1 if x > 0 else 1 << 31
        while num != 0:
            r = r * 10 + num % 10
            if r > bianjie: return 0
            num //= 10
        return r if x > 0 else -r
        # @lc code=end
